package com.instwall.callbase.thread;

public class BasicThread extends Thread {
    private Looper mLooper;
    private WorkQueue workQueue;

    public BasicThread(String threadName) {
        workQueue = new WorkQueue();
        mLooper = new Looper(workQueue);
        this.setName(threadName);
    }

    @Override
    public void run() {
        super.run();
        mLooper.start();
    }

    public void postTask(ITask task) {
        if (task != null) {
            workQueue.addQueue(task);
            synchronized (mLooper) {
                mLooper.notify();
            }
        }
    }

    public void release() {
        if (mLooper != null) {
            mLooper.stop();
        }
        if (workQueue != null) {
            workQueue.removeAll();
        }
        this.interrupt();
    }
}
